package test01;

import java.text.SimpleDateFormat;

import org.dozer.DozerBeanMapper;

/**
 * 基本类型：双方属性同类型同名称
 * @author Administrator
 *
 */
public class DozerTest01 {

	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {
		
		/**
		 * PO和VO的属性都是基本类型，且对应属性的类型和名称都相同：最简单，不需要任何配置
		 */
		DozerBeanMapper mapper = new DozerBeanMapper();
		
		//示例一：UserPO -> UserVO
		UserPO po1 = new UserPO();
		po1.setId(100);
		po1.setName("abc");
		po1.setAge(10);
		po1.setHeight(170.5F);
		po1.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2008-08-08"));
		
		UserVO vo1 = mapper.map(po1, UserVO.class);
		//UserVO vo1 = new UserVO(); mapper.map(po1, vo1);//另一方法
		
		System.out.println("示例一：由PO向VO转换");
		System.out.println("UserPO	->	UserVO");
		System.out.println(po1.getId()+"[int]    "+vo1.getId()+"[int]");
		System.out.println(po1.getName()+"[String]    "+vo1.getName()+"[String]");
		System.out.println(po1.getAge()+"[Integer]    "+vo1.getAge()+"[Integer]");
		System.out.println(po1.getHeight()+"[float]    "+vo1.getHeight()+"[float]");
		System.out.println(po1.getBirthday()+"[Date]    "+vo1.getBirthday()+"[Date]");
		
		//示例二：UserVO -> UserPO
		UserVO vo2 = new UserVO();
		vo2.setId(200);
		vo2.setName("cba");
		vo2.setAge(20);
		vo2.setHeight(170.5F);
		vo2.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2010-10-10"));
		
		UserPO po2 = mapper.map(vo2, UserPO.class);
		//UserPO po2 = new UserPO(); mapper.map(vo2, po2);//另一方法

		System.out.println("\n示例二：由VO向PO转换");
		System.out.println("UserVO	->	UserPO");
		System.out.println(vo2.getId()+"[int]    "+po2.getId()+"[int]");
		System.out.println(vo2.getName()+"[String]    "+po2.getName()+"[String]");
		System.out.println(vo2.getAge()+"[Integer]    "+po2.getAge()+"[Integer] ");
		System.out.println(vo2.getHeight()+"[float]    "+po2.getHeight()+"[float]");
		System.out.println(vo2.getBirthday()+"[Date]    "+po2.getBirthday()+"[Date]");
	}
}
